package thread;

import java.time.LocalDateTime;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author wuguojian
 * @description
 * @date 2022/3/8 6:05 下午
 **/
public class FutureTest {

    public static void main(String[] args) {
        System.out.println(LocalDateTime.now());
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        Future<Integer> result = executorService.submit(() -> {
            Thread.sleep(5000);
            return 1;
        });
        Future<Integer> result2 = executorService.submit(() -> {
            Thread.sleep(2000);
            return 2;
        });
        System.out.println("我可以做其他事情");
        try {
            System.out.println(result.get());
            System.out.println("-------");
            System.out.println(result2.get());
            System.out.println(LocalDateTime.now());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
